package com.itwlj.mapper;

import com.itwlj.entity.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {

    /**
     * 动态条件查询
     *
     * @param cart
     * @return
     */
    List<Cart> list(Cart cart);

    /**
     * 根据id修改商品数量
     *
     * @param cart
     */
    @Update("update cart set count = #{count} where id = #{id}")
    void updateCountById(Cart cart);

    /**
     * 插入购物测数据
     *
     * @param cart
     */
    @Insert("insert into cart(id, user_id, sku_id, name, attrs_text, picture, price, selected, count) " +
            "VALUES (#{id},#{userId},#{skuId},#{name},#{attrsText,},#{picture},#{price},#{selected},#{count})")
    void insert(Cart cart);

    /**
     * 根据skuId和用户id删除购物车数据
     */
    @Delete("delete from cart where sku_id = #{skuId} and user_id = #{userId}")
    void deleteBySkuId(Long skuId, Long userId);

    /**
     * 根据skuId和用户id修改购物车商品数量
     *
     * @param skuId
     * @param count
     * @param userId
     */
    @Update("update cart set count = #{count} where sku_id = #{skuId} and user_id = #{userId}")
    void updateCartCount(Long skuId, Long count, Long userId);
}
